#ifndef _OSAL_H_
#define _OSAL_H_

#if (SYS_OS_MODULE == ALI_TDS2)
#define __tds__
#endif

#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>

#ifdef __tds__
#include <osal/osal_task.h>
#include <osal/osal_mutex.h>
#include <osal/osal_flag.h>
#include <api/libtcpip/lwip/sockets.h>
#include <api/libc/printf.h>
#else
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <pthread.h>
#include <signal.h>
#include <fcntl.h>
#endif

typedef void *(*THREAD_ENTRY)(void *);

#ifdef __tds__
typedef void			*THREAD;
#define NULL_THREAD		NULL
typedef ID			MUTEX;
typedef ID			COND;
/*
typedef unsigned char 		uint8_t;
typedef unsigned short 		uint16_t;
typedef unsigned int 		uint32_t;
*/
#else
typedef pthread_t		THREAD;
#define NULL_THREAD		0
typedef pthread_mutex_t		MUTEX;
typedef pthread_cond_t		COND;
#endif

#ifndef SOMAXCONN
#define SOMAXCONN 128
#endif

THREAD thread_create_joinable(THREAD_ENTRY entry, void *param);
void thread_join(THREAD thread);

void MutexInit(MUTEX *mutex);
void MutexLock(MUTEX *mutex);
void MutexUnlock(MUTEX *mutex);
void MutexDestroy(MUTEX *mutex);

void CondInit(COND *cond);
void CondWait(COND *cond, MUTEX *mutex);
int  CondWaitTimeout(COND *cond, MUTEX *mutex, int msec);
void CondNotify(COND *cond);
void CondNotifyAll(COND *cond);
void CondDestroy(COND *cond);

#endif //_OSAL_H_
